﻿namespace OboutInc.Splitter2
{
    using System;
    using System.ComponentModel;
    using System.Web.UI;

    [ToolboxItem(false), Browsable(false), ParseChildren(true), PersistChildren(true)]
    public class HorizontalSplitterPanel : Control, INamingContainer
    {
        private OboutInc.Splitter2.CSSDetails _CSSDetails;
        private enumSplitterPanelType _panelType;

        public HorizontalSplitterPanel()
        {
        }

        public HorizontalSplitterPanel(enumSplitterPanelType _splitterPanelType)
        {
            this._panelType = _splitterPanelType;
        }

        protected override void OnInit(EventArgs e)
        {
            if (this.Header != null)
            {
                this.Controls.Add(this.Header);
            }
            this.Controls.Add(this.Content);
            if (this.Footer != null)
            {
                this.Controls.Add(this.Footer);
            }
            base.OnInit(e);
        }

        protected override void Render(HtmlTextWriter writer)
        {
            this.Header.CSSClass = this.CSSDetails.CSSPanelHeader;
            this.Header.ControlID = base.NamingContainer.ClientID;
            this.Header.RenderControl(writer);
            this.Content.CSSClass = this.CSSDetails.CSSPanelContent;
            this.Content.ControlID = base.NamingContainer.ClientID;
            this.Content.RenderControl(writer);
            this.Footer.CSSClass = this.CSSDetails.CSSPanelFooter;
            this.Footer.ControlID = base.NamingContainer.ClientID;
            this.Footer.RenderControl(writer);
        }

        [PersistenceMode(PersistenceMode.InnerProperty), Browsable(false)]
        public SplitterPanelComponent Content
        {
            get
            {
                if (this.ViewState["PanelContent"] == null)
                {
                    this.ViewState["PanelContent"] = new SplitterPanelComponent(this._panelType);
                }
                return (SplitterPanelComponent) this.ViewState["PanelContent"];
            }
        }

        internal string ContentUrl
        {
            get
            {
                return this.Content.Url;
            }
        }

        internal OboutInc.Splitter2.CSSDetails CSSDetails
        {
            get
            {
                return this._CSSDetails;
            }
            set
            {
                this._CSSDetails = value;
            }
        }

        [Browsable(false), PersistenceMode(PersistenceMode.InnerProperty)]
        public SplitterPanelComponent Footer
        {
            get
            {
                if (this.ViewState["PanelFooter"] == null)
                {
                    this.ViewState["PanelFooter"] = new SplitterPanelComponent(enumSplitterComponentType.Footer, this._panelType);
                }
                return (SplitterPanelComponent) this.ViewState["PanelFooter"];
            }
        }

        internal string FooterUrl
        {
            get
            {
                return this.Footer.Url;
            }
        }

        [PersistenceMode(PersistenceMode.InnerProperty), Browsable(false)]
        public SplitterPanelComponent Header
        {
            get
            {
                if (this.ViewState["PanelHeader"] == null)
                {
                    this.ViewState["PanelHeader"] = new SplitterPanelComponent(enumSplitterComponentType.Header, this._panelType);
                }
                return (SplitterPanelComponent) this.ViewState["PanelHeader"];
            }
        }

        internal string HeaderUrl
        {
            get
            {
                return this.Header.Url;
            }
        }

        [Category("Horizontal Splitter settings"), Bindable(true), Description("Default height of the panel."), DefaultValue(200)]
        public int HeightDefault
        {
            get
            {
                object obj2 = this.ViewState["HeightDefault"];
                if ((obj2 != null) && (((int) obj2) >= 0))
                {
                    return (int) obj2;
                }
                return 200;
            }
            set
            {
                this.ViewState["HeightDefault"] = value;
            }
        }

        [Bindable(true), DefaultValue(-1), Category("Horizontal Splitter settings"), Description("Maximum height of the panel. The other panel takes up remaining width.")]
        public int HeightMax
        {
            get
            {
                object obj2 = this.ViewState["HeightMax"];
                if (obj2 != null)
                {
                    return (int) obj2;
                }
                return -1;
            }
            set
            {
                this.ViewState["HeightMax"] = value;
            }
        }

        [Bindable(true), Description("Minimum height of the panel. The other panel takes up remaining width."), Category("Horizontal Splitter settings"), DefaultValue(-1)]
        public int HeightMin
        {
            get
            {
                object obj2 = this.ViewState["HeightMin"];
                if (obj2 != null)
                {
                    return (int) obj2;
                }
                return -1;
            }
            set
            {
                this.ViewState["HeightMin"] = value;
            }
        }

        internal bool IsHeightDefaultSet
        {
            get
            {
                object obj2 = this.ViewState["HeightDefault"];
                return ((obj2 != null) && (((int) obj2) >= 0));
            }
        }
    }
}

